/**
 * 网页截图
 * address = system.args[1];//传入的URL地址
 * output = system.args[2];//保存的图片路径
 * @Author Canaan
 * @Date 2017/12/4.
 */
var page = require('webpage').create(), system = require('system'), address, output, size;

if (system.args.length < 3 || system.args.length > 5) {
    phantom.exit(1);
} else {
    address = system.args[1];
    output = system.args[2];
    //定义宽高
    page.viewportSize = {
        width : 800,
        height: 600
    };
    page.open(address, function (status) {
        var bb = page.evaluate(function () {
            return document.getElementsByTagName('html')[0].getBoundingClientRect();
        });
        page.clipRect = {
            top   : bb.top,
            left  : bb.left,
            width : bb.width,
            height: bb.height
        };
        page.render(output);
        page.close();
        console.log('success');
        // window.setTimeout(function() {
        //     page.render(output);
        //     page.close();
        //     console.log('success');
        // }, 1000);
    });
}
